//
//  StyViewController.m
//  HomeFurnishing
//
//  Created by dllo on 16/3/25.
//  Copyright © 2016年 YMing. All rights reserved.
//

#import "StyViewController.h"
#import "StyTableViewCell.h"
#import "ActivitySrcollView.h"
#import "StyBaseModel.h"
#import "DetailStyVC.h"
@interface StyViewController ()<UITableViewDelegate, UITableViewDataSource>
@property(nonatomic, retain) UITableView *tableView;
@property(nonatomic, retain) NSArray *dataArr;
@end

@implementation StyViewController

-(void)dealloc
{
    [_tableView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"装修攻略";
    [self createTableView];
    [self createView];
    [self dataHandle];
}
/**
 *  添加数据
 */
-(void)dataHandle
{
    [NetworkHandle GetDataWithURL:@"http://api.guju.com.cn/v2/strategy/strategyList?userId=0&count=10&start=0&orderString=CATEGORY&category=0" dic:nil success:^(id responseObject) {
        self.dataArr = [StyBaseModel transformWithArray:responseObject[@"strategyList"]];
        [_tableView reloadData];
    } filed:^(NSError *error) {
        
    }];
}

/**
 *  添加tableView
 */
-(void)createTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 49) style:(UITableViewStylePlain)];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.tableFooterView =[[UIView alloc] init];
    [_tableView release];
    [self.view addSubview:_tableView];
    [_tableView registerClass:[StyTableViewCell class] forCellReuseIdentifier:@"StyCell"];
    _tableView.rowHeight = 150;
    
            
}
/**
 *  添加轮播图
 */
-(void)createView
{
    ActivitySrcollView *cf = [[ActivitySrcollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];
    NSArray *imageArr = @[@"http://productpic.qiniudn.com/taotu_36_2014_08_21.NO002.jpg",@"http://productpic.qiniudn.com/taotu_35_2014_08_21.NO001.jpg",@"http://productpic.qiniudn.com/taotu_180_2014_09_26.NO001.jpg",@"http://productpic.qiniudn.com/taotu_172_2014_09_26.NO006.jpg",@"http://productpic.qiniudn.com/taotu_114_2014_08_29.NO003.jpg",@"http://productpic.qiniudn.com/taotu_22_2014_08_21.NO001.jpg",@"http://productpic.qiniudn.com/taotu_188_2014_09_28.NO002.jpg",@"http://productpic.qiniudn.com/taotu_38_2014_08_21.NO001.jpg"];
    [cf setImages:[imageArr mutableCopy]];
    _tableView.tableHeaderView = cf;
    [cf release];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    StyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"StyCell" forIndexPath:indexPath];
    StyBaseModel *m = _dataArr[indexPath.row];
    cell.title.text = m.title;
    cell.details.text = m.descrip;
    cell.style.text = m.categoryName;
    NSString *str = [NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w640_h0_m0.jpg",m.covorPhotoId];
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:str]];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailStyVC *VC = [[DetailStyVC alloc] init];
    StyBaseModel *m = _dataArr[indexPath.row];
    VC.mId = m.mId;
    [self.navigationController pushViewController:VC animated:YES];
    [VC release];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
